from django.urls import path, include
from django.contrib.auth import views as auth_views
from rest_framework import routers
from .custom_router import NoRootAPIRouter
from .views import views, course, experiment, image, exam, order, experiment, gov, report
from django.views.decorators.csrf import csrf_exempt
from rest_framework_swagger.views import get_swagger_view

schema_view = get_swagger_view(title='Pastebin API')

router = NoRootAPIRouter()
router.register(r'users', views.UserViewSet)
router.register(r'groups', views.GroupViewSet)
router.register(r'students', views.StudentListViewSet)
router.register(r'teachers', views.TeacherListViewSet)
router.register(r'experts', views.ExpertListViewSet)
router.register(r'knowledges', views.KnowledgeViewSet)

router_objects = NoRootAPIRouter()
router_objects.register(r'classes', views.ClassListViewSet)
router_objects.register(r'schools', views.SchoolListViewSet)
router_objects.register(r'colleges', views.CollegeListViewSet)
router_objects.register(r'majors', views.MajorListViewSet)
router_objects.register(r'knowledges', views.KnowledgeListViewSet)
router_objects.register(r'courses', views.CourseListViewSet)
router_objects.register(r'experiments', experiment.ExperimentListViewSet)
router_objects.register(r'environments', views.EnvironmentListViewSet)
router_objects.register(r'images', image.ImageListViewSet)
router_objects.register(r'tempinstances', image.TempInstanceListAPIView)
router_objects.register(r'knowledges/search', views.KnowledgeSearchListViewSet)
router_objects.register(r'questions', views.QuestionListViewSet)
router_objects.register(r'reports', experiment.ReportListViewSet)
router_objects.register(r'papers', exam.PaperListViewSet)
router_objects.register(r'exams', views.ExamListViewSet)

router_stu = NoRootAPIRouter()
router_stu.register(r'achievement', views.AchievementListViewSet)
router_stu.register(r'courses', views.StuCourseListViewSet)
router_stu.register(r'open/courses', views.OpenCourseListViewSet)
router_stu.register(r'experiments', views.StuExperimentListViewSet)
router_stu.register(r'exams', views.StuExamListViewSet)

# 教师端专有接口
""" router_objects.register(r'questions', views.QuestionListViewSet)
 """



urlpatterns = [
    # path('api-auth/', include('rest_framework.urls')),
    path('docs/', schema_view),
    path('', include('django.contrib.auth.urls')),
    path('object/', include(router_objects.urls)),
    path('user/', include(router.urls)),
    path('sso/getTk/', views.SsoGetTicketViewSet.as_view()),
    path('sso/getUserinfo/', views.SsoGetUserInfoViewSet.as_view()),
    path('stu/', include(router_stu.urls)),
    path('user/profile/', csrf_exempt(views.UserProfileViewSet.as_view({'get': 'retrieve'}))),
    path('ajax/logout/', csrf_exempt(views.LogoutViewSet.as_view())),
    path('ajax/login', csrf_exempt(views.LoginViewSet.as_view()), name='login'),
    path('cas/login', views.CasLoginCallback, name='cas-login'),
    path('user/teacher/view/<int:userid>/', views.TeacherOneViewSet.as_view({'get': 'retrieve'})),
    path('user/teacher/create/', csrf_exempt(views.TeacherCreateViewSet.as_view({'post': 'create'}))),
    path('user/teacher/update/<int:user__id>/', csrf_exempt(views.TeacherUpdateViewSet.as_view({'post': 'update'}))),
    path('user/teacher/batch/block/', csrf_exempt(views.TeacherBlockView.as_view())),
    path('school/list/', csrf_exempt(views.FuzzySearchSchoolView.as_view())),
    path('college/list/', csrf_exempt(views.FuzzySearchCollegeView.as_view())),
    path('major/list/', csrf_exempt(views.FuzzySearchMajorView.as_view())),
    path('class/list/', csrf_exempt(views.FuzzySearchClassView.as_view())),
    path('user/student/create/', csrf_exempt(views.StudentCreateViewSet.as_view({'post': 'create'}))),
    path('user/student/view/<int:userid>/', views.StudentOneViewSet.as_view({'get': 'retrieve'})),
    path('user/student/update/<int:user__id>/', csrf_exempt(views.StudentUpdateViewSet.as_view({'post': 'update'}))),
    path('user/student/batch/block/', csrf_exempt(views.StudentBlockView.as_view())),
    path('user/expert/view/<int:userid>/', views.ExpertOneViewSet.as_view({'get': 'retrieve'})),
    path('user/expert/create/', csrf_exempt(views.ExpertCreateViewSet.as_view({'post': 'create'}))),
    path('user/expert/update/<int:user__id>/', csrf_exempt(views.ExpertUpdateViewSet.as_view({'post': 'update'}))),
    path('user/expert/batch/block/', csrf_exempt(views.ExpertBlockView.as_view())),
    path('user/batch/create/', csrf_exempt(views.FileUploadView.as_view())),
    # 新建班级
    path('object/class/create/', csrf_exempt(views.ClassCreateViewSet.as_view({'post': 'create'}))),
    # 查看班级详情
    path('object/class/<int:class_id>/', views.ClassOneViewSet.as_view({'get': 'retrieve'})),
    # 修改班级信息
    path('object/class/update/<int:id>/', csrf_exempt(views.ClassUpdateViewSet.as_view({'post': 'update'}))),
    # 班级批量封停
    path('object/class/batch/block/', csrf_exempt(views.ClassBlockView.as_view())),
    # 班级批量添加学生
    path('object/class/batch/add/', csrf_exempt(views.ClassAddView.as_view())),
    # 课程章节列表
    path('object/course/chapter/<int:course_id>/', csrf_exempt(views.ChapterListAPIView.as_view())),
    # 课程章节添加/删除
    path('object/course/chapter/add/', csrf_exempt(course.ChapterAddView.as_view())),
    # 新建课程
    path('object/course/create/', csrf_exempt(views.CourseCreateViewSet.as_view())),
    # 查看课程详情
    path('object/course/<int:course_id>/', views.CourseOneViewSet.as_view({'get': 'retrieve'})),
    # 修改课程课程
    path('object/course/update/<int:id>/', csrf_exempt(views.CourseUpdateViewSet.as_view({'post': 'update'}))),
    # 课程批量封停
    path('object/course/batch/block/', csrf_exempt(views.CourseBlockView.as_view())),
    path('object/chapter/batch/block/', csrf_exempt(views.ChapterBlockView.as_view())),
    # 章节详情
    path('object/chapter/<int:chapter_id>/', course.ChapterOneViewSet.as_view({'get': 'retrieve'})),
    # 修改章节
    path('object/chapter/update/<int:id>/', csrf_exempt(views.ChapterUpdateViewSet.as_view({'post': 'update'}))),
    # 课程实验列表
    # path('object/course/experiment/<int:course_id>/', csrf_exempt(views.ExperimentListAPIView.as_view())),
    # 选课学生列表
    path('object/course/student/<int:course_id>/', csrf_exempt(course.CourseStudentListAPIView.as_view())),
    # 授课教师列表
    path('object/course/teacher/<int:course_id>/', csrf_exempt(views.CourseTeacherListAPIView.as_view())),
    # 课程添加/删除选课学生
    path('object/course/student/add/', csrf_exempt(views.CourseAddStudentView.as_view())),
    # 课程添加/删除授课教师
    path('object/course/teacher/add/', csrf_exempt(views.CourseAddTeacherView.as_view())),
    path('object/batch/create/', csrf_exempt(views.ObjectFileUploadView.as_view())),
    # 学校管理
    # 新建学校
    path('object/school/create/', csrf_exempt(views.SchoolCreateViewSet.as_view({'post': 'create'}))),
    # 修改学校
    path('object/school/update/<int:id>/', csrf_exempt(views.SchoolUpdateViewSet.as_view({'post': 'update'}))),
    # 查看学校详情
    path('object/school/<int:school_id>/', views.SchoolOneViewSet.as_view({'get': 'retrieve'})),
    # 学院管理
    # 新建学院
    path('object/college/create/', csrf_exempt(views.CollegeCreateViewSet.as_view({'post': 'create'}))),
    # 修改学院
    path('object/college/update/<int:id>/', csrf_exempt(views.CollegeUpdateViewSet.as_view({'post': 'update'}))),
    # 查看学院详情
    path('object/college/<int:college_id>/', views.CollegeOneViewSet.as_view({'get': 'retrieve'})),
    # 新建专业
    path('object/major/create/', csrf_exempt(views.MajorCreateViewSet.as_view({'post': 'create'}))),
    # 修改专业
    path('object/major/update/<int:id>/', csrf_exempt(views.MajorUpdateViewSet.as_view({'post': 'update'}))),
    # 查看专业详情
    path('object/major/<int:major_id>/', views.MajorOneViewSet.as_view({'get': 'retrieve'})),
    # 新建/删除/编辑知识点
    path('object/knowledge/create/', csrf_exempt(views.KnowledgeAddView.as_view())),
    # 上传富文本图片
    path('object/richtext/image/upload/', csrf_exempt(views.ImageUploadViewSet.as_view())),
    # 实验管理
    # 查看实验详情
    path('object/experiment/<int:experiment_id>/', experiment.ExperimentOneViewSet.as_view({'get': 'retrieve'})),
    # 查看实验环境详情
    path('object/environment/<int:environment_id>/', experiment.EnvironmentOneViewSet.as_view({'get': 'retrieve'})),
    path('object/experiment/status/set/', experiment.ExperimentSetStatus.as_view()),
    # 修改实验show字段
    path('object/experiment/show/set/', experiment.ExperimentSetShow.as_view()),
    # 修改密码
    path('object/resetpassword/', experiment.ReSetPassWord.as_view()),
    # 实验环境实例列表
    path('object/environment/instance/<int:environment_id>/', experiment.InstanceListAPIView.as_view()),
    # 实例批量回收
    path('object/instance/batch/recovery/', csrf_exempt(experiment.InstanceRecoveryView.as_view())),
    # 实例批量关机
    path('object/instance/batch/shutdown/', csrf_exempt(views.InstanceShutdownView.as_view())),
    # 实例批量开机
    path('object/instance/batch/startup/', csrf_exempt(views.InstanceStartUpView.as_view())),
    # 实例批量创建
    path('object/instance/batch/create/', csrf_exempt(views.InstanceCreateView.as_view())),
    # 下发实例
    path('object/environment/issue/', csrf_exempt(views.EnvironmentIssueView.as_view())),
    # 模糊查询镜像
    path('object/image/list/', csrf_exempt(views.FuzzySearchImageView.as_view())),
    # 创建镜像（外部导入）
    path('object/image/import/', csrf_exempt(views.ImageImportViewSet.as_view())),
    path('object/image/createimport/', csrf_exempt(views.ImageCreateImportViewSet.as_view())),
    path('object/image/upload/', csrf_exempt(views.CvmImageUploadViewSet.as_view())),
    path('cos/sts/', csrf_exempt(views.CosUploadStsView.as_view())),
    path('cos/sign/', csrf_exempt(views.CosSignView.as_view())),
    path('object/image/describe/', csrf_exempt(views.DescImportImageViewSet.as_view())),
    # 创建镜像（手动创建第一步）
    path('object/image/create/first/', csrf_exempt(image.ImageCreateFirstView.as_view())),
    # 创建镜像（手动创建第二步）
    path('object/image/create/second/', csrf_exempt(image.ImageCreateSecondView.as_view())),
    # 创建镜像（手动创建第三步）
    path('object/image/create/third/', csrf_exempt(image.ImageCreateThirdView.as_view())),
    # 修改基础镜像（第一步）
    path('object/image/modify/first/', csrf_exempt(views.ImageModifyFirstView.as_view())),
    # 修改基础镜像（第二步）
    path('object/image/modify/second/', csrf_exempt(views.ImageModifySecondView.as_view())),
    # 修改基础镜像（第三步）
    path('object/image/modify/third/', csrf_exempt(views.ImageModifyThirdView.as_view())),
    # 开机、关机、回收虚拟机
    path('object/tempins/action/', csrf_exempt(image.InstanceActionView.as_view())),
    # 回收临时虚拟机
    path('object/tempins/cancel/', csrf_exempt(image.CancelInstance.as_view())),
    # 删除自定义镜像
    path('object/my/image/del/', csrf_exempt(image.DeleteMyImage.as_view())),
    # 按钮手动同步镜像
    path('object/my/image/async/', csrf_exempt(image.AsyncImage.as_view())),
    # 查看镜像详情
    path('object/image/<int:image_id>/', views.ImageOneViewSet.as_view({'get': 'retrieve'})),
    # 镜像批量删除
    path('object/image/batch/remove/', csrf_exempt(views.ImageRemoveView.as_view())),
    # 学生实验成绩列表
    path('object/experiment/student/<int:course_id>/<int:student_id>', csrf_exempt(views.ExperimentScoreListAPIView.as_view())),
    # 学生考试成绩列表
    path('object/exam/student/<int:course_id>/<int:student_id>', csrf_exempt(views.ExamScoreListAPIView.as_view())),
    # 教师专有接口
    # 新建实验
    path('object/experiment/create/', experiment.ExperimentCreate.as_view(), name='ExperimentCreate'),
    # 新建实验（暂不使用）
    # path('object/experiment/createnew/', experiment.ExperimentCreate2.as_view(), name='ExperimentCreate2'),
    # 编辑实验
    path('object/experiment/update/<int:pk>/', experiment.ExperimentEdit.as_view(), name='ExperimentEdit'),
    path('object/experiment/update/desc/<int:pk>/', experiment.ExperimentEditDesc.as_view(), name='ExperimentEdit'),
    # 获取实验环境
    path('object/experiment/env/<int:pk>/', experiment.ExperimentEnv.as_view()),
    # 新建实验环境
    path('object/environment/create/', experiment.EnvironmentCreateViewSet.as_view({'post': 'create'})),
    # 编辑实验环境
    path('object/environment/update/<int:id>/', csrf_exempt(views.EnvironmentUpdateViewSet.as_view({'post': 'update'}))),
    # 实验批量删除
    path('object/experiment/batch/remove/', csrf_exempt(views.ExperimentRemoveView.as_view())),
    # 实验环境批量删除
    path('object/environment/batch/remove/', csrf_exempt(views.EnvironmentRemoveView.as_view())),
    # 新建简答题
    path('object/blankquestion/create/', csrf_exempt(views.BlankQuestionCreateViewSet.as_view({'post': 'create'}))),
    # 新建选择题
    path('object/choicequestion/create/', csrf_exempt(views.ChoiceQuestionCreateViewSet.as_view({'post': 'create'}))),
    # id查看知识点
    path('object/knowledge/<int:knowledge_id>/', views.KnowledgeOneViewSet.as_view({'get': 'retrieve'})),
    # id查看选择题选项
    path('object/optiondetail/<int:optiondetail_id>/', views.OptionDetailOneViewSet.as_view({'get': 'retrieve'})),
    # 查看选择题详情
    path('object/choicequestion/<int:question_id>/', views.ChoiceQuestionOneViewSet.as_view({'get': 'retrieve'})),
    # 查看简答题详情
    path('object/blankquestion/<int:question_id>/', views.BlankQuestionOneViewSet.as_view({'get': 'retrieve'})),
    # 修改选择题
    path('object/choicequestion/update/<int:id>/', csrf_exempt(views.ChoiceQuestionUpdateViewSet.as_view({'post': 'update'}))),
    # 创建选择题选项
    path('object/optiondetail/create/', csrf_exempt(views.OptionDetailCreateViewSet.as_view({'post': 'create'}))),
    # 修改简答题
    path('object/blankquestion/update/<int:id>/', csrf_exempt(views.BlankQuestionUpdateViewSet.as_view({'post': 'update'}))),
    # 题目批量删除
    path('object/question/batch/remove/', csrf_exempt(views.QuestionRemoveView.as_view())),
    # 查看实验报告详情
    path('object/report/<int:report_id>/', views.ReportOneViewSet.as_view({'get': 'retrieve'})),
    # 查看实验报告详情
    path('object/report/download/<int:report_id>/', views.ReportDownloadViewSet.as_view({'get': 'retrieve'})),
    # 实验报告评分
    path('object/report/score/<int:id>/', csrf_exempt(views.ReportScoreUpdateViewSet.as_view({'post': 'update'}))),
    # # 实验报告评分
    # path('object/report/score/<int:id>/', csrf_exempt(views.ReportScoreUpdateViewSet.as_view({'post': 'update'}))),
    # 教师创建考试、组卷（自动、手动）
    path('object/exam/autocreate/', csrf_exempt(exam.ExamCreateViewSet.as_view({'post': 'create'}))),
    # 教师创建考试、组卷（手动）
    path('object/exam/manualcreate/', csrf_exempt(views.ExamManualCreateViewSet.as_view({'post': 'create'}))),
    # 查看试卷详情
    path('object/exam/<int:exam_id>/', exam.ExamOneViewSet.as_view({'get': 'retrieve'})),
    # 查看试卷详情
    path('object/exam/action/<int:exam_id>/', exam.ExamStatusAction.as_view()),
    # 试卷添加考题
    path('object/examquestion/add/', csrf_exempt(exam.ExamQuestionAddView.as_view())),
    # 试卷删除考题
    path('object/examquestion/remove/', csrf_exempt(exam.ExamQuestionRemoveView.as_view())),
    # 编辑试卷
    path('object/exam/update/<int:id>/', csrf_exempt(views.ExamUpdateViewSet.as_view({'post': 'update'}))),
    # 查看学生试卷详情
    path('object/paper/<int:paper_id>/', views.PaperOneViewSet.as_view({'get': 'retrieve'})),
    # 编辑试卷成绩
    path('object/paper/update/<int:id>/', csrf_exempt(views.PaperUpdateViewSet.as_view({'post': 'update'}))),
    #  学生考题打分
    path('object/paperquestion/update/<int:id>/', csrf_exempt(views.PaperQuestionUpdateViewSet.as_view({'post': 'update'}))),
    # 学生专有接口
    # 学生查看课程详情
    path('stu/course/<int:course_id>/', views.StuCourseOneViewSet.as_view({'get': 'retrieve'})),
    # 学生查看章节详情
    path('stu/chapter/<int:chapter_id>/', views.StuChapterOneViewSet.as_view({'get': 'retrieve'})),
    # 学生查看实验报告详情
    path('stu/report/<int:report_id>/', views.StuReportOneViewSet.as_view({'get': 'retrieve'})),
    # 学生查看实验详情
    path('stu/experiment/<int:experiment_id>/', views.StuExperimentOneViewSet.as_view({'get': 'retrieve'})),
    # 网速测试
    path('stu/experiment/test-speed', views.TestSpeed.as_view({'get': 'retrieve'})),
    #查询虚拟机内存占用情况
    path('stu/experiment/df-h/', views.MemoryUsage.as_view({'get': 'retrieve'})),
    #下载文件
    path('stu/experiment/file-download/', views.FileDownload.as_view({'get': 'retrieve'})),
    #查询文件中转站内容
    path('stu/experiment/filetransfer-station-files', views.FileTransferStationFiles.as_view({'get': 'retrieve'})),
    #文件上传到虚拟机
    path('stu/experiment/file-upload/<str:ip>', csrf_exempt(views.FileUpload.as_view({'post': 'create'}))),
    # 学生查看试卷详情
    path('stu/exam/<int:exam_id>/', views.StuExamOneViewSet.as_view({'get': 'retrieve'})),
    # 学生查看试卷详情
    path('stu/paper/<int:exam_id>/', views.StuPaperOneViewSet.as_view({'get': 'retrieve'})),
    #path('stu/paper/<int:paper_id>/', views.StuPaperOneViewSet.as_view({'get': 'retrieve'})),
    # 学生主动获取试卷
    path('stu/paper/create/', csrf_exempt(views.StuPaperCreateView.as_view())),
    # 学生提交选择题答案
    path('stu/choice/answer/', csrf_exempt(views.StuChoiceAnswerView.as_view())),
    # 学生提交填空题答案
    path('stu/blank/answer/', csrf_exempt(views.StuBlankAnswerView.as_view())),
    # 学生提交试卷（结束答题并自动判题）
    path('stu/paper/submit/', csrf_exempt(views.StuPaperSubmitView.as_view())),
    # 学生提交实验报告
    path('stu/report/create/', views.StuReportCreateViewSet.as_view({'post': 'create'})),
    # 学生选择公开课
    path('stu/course/choice/', views.StudentChoiceCourseView.as_view()),
    # 学生操作虚拟机实例
    path('stu/instance/action/', csrf_exempt(views.StudentInstanceActionView.as_view())),
    path('orders/', order.Orders.as_view({'get': 'list'}), name='orders'),
    path('pc/vnc/', csrf_exempt(experiment.PcVNCView.as_view()), name='pcvnc'),
    path('pc/report/create', report.ReportCreateView.as_view(), name="pcCreateReport"),
    path('gov/create/', gov.GovCreate.as_view(), name='govCreate'),
    path('gov/<int:pk>/', csrf_exempt(gov.GovDetail.as_view({'get': 'retrieve'})), name='gov'),
    path('gov/update/<int:pk>/', gov.GovUpdate.as_view(), name='govUpdate'),
    path('gov/del/', gov.GovDelete.as_view(), name='govDel'),
    path('gov/list/', gov.GovList.as_view({'get': 'list'}), name='govList'),
    path('gov/course/create/', gov.GovCourseCreate.as_view(), name='govCourseCreate'),
    path('gov/course/list/', gov.GovCourseList.as_view({'get': 'list'}), name='govCourseList'),
    path('ins/event/', experiment.InsEventView.as_view(), name='insevent'),
    path('logstash/', experiment.LogstashView.as_view(), name='logstash'),
    path('logstash/list', experiment.LogstashListView.as_view(), name='logstashList'),
]
